﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LotteryVote.Utility;

namespace LotteryVote.Entity
{
    public class User : IEntity
    {
        private SystemRole _role;

        public const string TABLENAME = "tb_User";
        public const string USERID = "UserId";
        public const string ROLEID = "RoleId";
        public const string USERNAME = "UserName";
        public const string PARENTID = "ParentId";

        public int UserId { get; set; }
        public int RoleId { get; set; }
        public string UserName { get; set; }
        public int ParentId { get; set; }
        public DateTime? LastLoginTime { get; set; }
        public UserInfo UserInfo { get; set; }
        public SystemRole Role
        {
            get
            {
                if (_role == default(SystemRole))
                    _role = EnumHelper.GetEnum<SystemRole>(RoleId.ToString());
                return _role;
            }
        }
        public IList<UserCommission> UserCommission { get; set; }
        public void LoadUserCommission(Func<IList<UserCommission>> action)
        {
            UserCommission = action();
        }
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("{0}:{1}", USERID, UserId);
            sb.AppendFormat("{0}:{1}", ROLEID, RoleId);
            sb.AppendFormat("{0}:{1}", USERNAME, UserName);
            sb.AppendFormat("{0}:{1}", PARENTID, ParentId);
            return sb.ToString();
        }
    }
}
